#pragma once

#include <d3d9.h>
#include <d3dx9.h>
#include "DirectInput.h"
#include <string>

#define SAFE_RELEASE(x) if(x) {x->Release(); x = 0;}
enum States{TITLE, MAIN, OPTIONS, CREDITS, CHARACTERSELECT, LEVELSELECT, LEVELONE,LEVELTWO,LEVELTHREE, PAUSED, DEATH, WIN};
enum Selection{QUITBUTTON, PLAYBUTTON, OPTIONSBUTTON, CREDITSBUTTON, WINDOWEDBUTTON, FULLSCREENBUTTON, BRAWNS, BRAINS, ONE, TWO, THREE, FOUR, FIVE, SIX, SEVEN, EIGHT, NINE, ZERO, GO, BLANK};

class Menu
{
	ID3DXSprite* m_Sprite;//sprite object
	IDirect3DTexture9* m_TitleScreenTexture;//texture 1
	IDirect3DTexture9* m_QuitButton;//texture 2
	IDirect3DTexture9* m_PlayButton;//texture 3
	IDirect3DTexture9* m_OptionsButton;//texture 4
	IDirect3DTexture9* m_CreditButton;//texture 5
	IDirect3DTexture9* m_TitleButton;//texture 6
	IDirect3DTexture9* m_OptionsScreenTexture;//texture 7
	IDirect3DTexture9* m_CreditsScreenTexture;//texture 8
	IDirect3DTexture9* m_CharacterSelectScreenTexture;//texture 9
	IDirect3DTexture9* m_LevelSelectScreenTexture;//texture 10
	IDirect3DTexture9* m_PausedScreenTexture;//texture 11
	IDirect3DTexture9* m_DeathScreenTexture;//texture 12
	IDirect3DTexture9* m_WinScreenTexture;//texture 13
	IDirect3DTexture9* m_WindowedButtonTexture;//texture 14
	IDirect3DTexture9* m_FullScreenButtonTexture;//texture 15
	IDirect3DTexture9* m_BrawnsButtonTexture;//texture 16
	IDirect3DTexture9* m_BrainsButtonTexture;//texture 17
	IDirect3DTexture9* m_OneButtonTexture;//texture 18
	IDirect3DTexture9* m_TwoButtonTexture;//texture 19
	IDirect3DTexture9* m_ThreeButtonTexture;//texture 20
	IDirect3DTexture9* m_FourButtonTexture;//texture 21
	IDirect3DTexture9* m_FiveButtonTexture;//texture 22
	IDirect3DTexture9* m_SixButtonTexture;//texture 23
	IDirect3DTexture9* m_SevenButtonTexture;//texture 24
	IDirect3DTexture9* m_EightButtonTexture;//texture 25
	IDirect3DTexture9* m_NineButtonTexture;//texture 26
	IDirect3DTexture9* m_ZeroButtonTexture;//texture 27
	IDirect3DTexture9* m_GoButtonTexture;//texture 28
	IDirect3DTexture9* m_BlankButtonTexture;//texture 29
	IDirect3DTexture9* m_TextBoxTexture;//texture 30

	bool windowed;
	States currState;
	Selection selection;

	D3DXMATRIX worldMat;//world matrix used for setting the transform
	D3DXMATRIX rotMat;//rotation matrix
	D3DXMATRIX scaMat;//scaling matrix
	D3DXMATRIX transMat;//translation matrix

	DirectInput* inputs;
	bool keyDown[256];//is going to be used for the check on single button press

	std::string levelCode;
	int currCodeValue;

public:

	int chosenCharacter;
	Menu(void);
	~Menu(void);

	//create the menu sprites as well as the input class to see if the selection was used.
	void createMenu(IDirect3DDevice9* m_pD3DDevice, DirectInput* input);

	//when the framework is done, destroy all of the textures and devices that are used.
	void destroyMenu();

	//This is the render for the menu, and based on the state it displays the correct
	States displayMenu(States state, States currentState);
	
	
	//calls the necessary sprite information needed to draw the screens
	void drawTitleScreen();
	void drawMainMenu();
	void drawOptionsScreen();
	void drawCreditsScreen();
	void drawCharacterSelect();
	void drawLevelSelect();
	void drawPausedScreen();
	void drawDeathScreen();
	void drawWinScreen();

	//clear all of the matrices in order to translate rotate and scale them separately
	void clearMatrices();
	
	//uses the input so that keys are recognized in the states its in
	States titleInput();
	States mainMenuInput();
	States optionsInput();
	States creditsInput();
	States characterSelectInput();
	States levelSelectInput();
	States pausedInput(States currentState);
	States deathInput();
	States winInput();

	//this checks the code for the level select
	States codeCheck();

	//if the device is lost, call the onlostdevice method of the items that need it
	void onLostDevice();

	//if the device is reset, call the onresetdevice method of the items that need it
	void onResetDevice();
	
};
